<?php

namespace App\Http\Controllers\Api;

use Illuminate\Http\Request;
use App\Models\User;
use App\Http\Controllers\Controller;

class LoginController extends Controller
{

    // 登录用户名标示为email字段
    public function username()
    {
        return 'email';
    }
    //登录接口，调用了ApiController中一些其他函数succeed\failed，上文未提及，用于接口格式化输出
    public function login(Request $request)
    {
        // 私有token
        //$user=User::find(1);
        $token = $user->createToken('token')->accessToken;
        return response()->json(['token_type'=>'Bearer','access_token'=>$token]);
    }
    public function getdata()
    {
       $data=\Auth::user()->toArray();
        return response()->json(['msg' => 'auth msg data'.date('Y-m-d H:i:s'),'data'=>$data]);
    }
    public function data()
    {
        return response()->json(['msg' => 'noauth msg data'.date('Y-m-d H:i:s')]);
    }
}
